<template>
  <div class="process-container">
    <!-- 头部导航 -->
    <div class="header">
      <div class="header-content">
        <router-link class="back-btn" to="/main/renshi/kaoqing/qingjia-list">
          <i class="el-icon-arrow-left"></i>
          <span>返回</span>
        </router-link>
        <h2 class="page-title">请假审批流程</h2>
      </div>
    </div>

    <!-- 流程图 -->
    <div class="process-timeline" v-loading="loading">
      <div v-for="(step, index) in processSteps" :key="index" class="process-step" 
           :class="{ 'completed': step.status === 'completed', 
                    'current': step.status === 'current',
                    'pending': step.status === 'pending' }">
        <!-- 步骤节点 -->
        <div class="step-node">
          <div class="step-icon">
            <i :class="getStepIcon(step.status)"></i>
          </div>
          <div class="step-content">
            <h3>{{ step.title }}</h3>
            <div class="step-info">
              <p v-if="step.approver">审批人：{{ step.approver }}</p>
              <p v-if="step.time">时间：{{ formatDateTime(step.time) }}</p>
              <p v-if="step.comment">意见：{{ step.comment }}</p>
            </div>
          </div>
        </div>
        <!-- 连接线 -->
        <div class="step-line" v-if="index !== processSteps.length - 1"></div>
      </div>
      <!-- 无数据提示 -->
      <div v-if="!loading && processSteps.length === 0" class="no-data">
        <i class="el-icon-warning"></i>
        <p>暂无流程数据</p>
      </div>
    </div>
  </div>
</template>

<script>
import { getLeaveApplicationProcess } from '@/api/leave'

export default {
  data() {
    return {
      processSteps: [],
      loading: false
    }
  },
  methods: {
    getStepIcon(status) {
      switch (status) {
        case 'completed':
          return 'el-icon-check';
        case 'current':
          return 'el-icon-loading';
        case 'pending':
          return 'el-icon-more';
        default:
          return 'el-icon-more';
      }
    },
    async fetchProcessData() {
      try {
        this.loading = true;
        const id = this.$route.query.id;
        if (!id) {
          this.$message.error('未找到请假申请ID');
          return;
        }
        
        const response = await getLeaveApplicationProcess(id);
        if (response.data) {
          this.processSteps = response.data.steps;
        }
      } catch (error) {
        console.error('获取流程数据失败:', error);
        this.$message.error('获取流程数据失败：' + (error.response?.data?.message || error.message));
      } finally {
        this.loading = false;
      }
    },
    formatDateTime(datetime) {
      if (!datetime) return '';
      const date = new Date(datetime);
      return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;
    }
  },
  created() {
    this.fetchProcessData();
  }
}
</script>

<style scoped>
.process-container {
  padding: 32px;
  background-color: #f4f7fa;
  min-height: 100vh;
}

.header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 40px;
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: relative;
}

.header-content {
  width: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-top: 10px;
}

.back-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  text-decoration: none;
  color: #606266;
  display: flex;
  align-items: center;
  padding: 8px 15px;
  border-radius: 4px;
  transition: all 0.3s ease;
  background-color: #f4f4f5;
  border: 1px solid #dcdfe6;
}

.back-btn:hover {
  color: #409EFF;
  background-color: #ecf5ff;
  border-color: #c6e2ff;
}

.back-btn i {
  margin-right: 5px;
  font-size: 14px;
}

.back-btn span {
  font-size: 14px;
}

.page-title {
  margin: 0;
  font-size: 24px;
  color: #303133;
  text-align: center;
}

.process-timeline {
  background: #fff;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.process-step {
  position: relative;
  padding-bottom: 40px;
}

.step-node {
  display: flex;
  align-items: flex-start;
}

.step-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 20px;
  flex-shrink: 0;
}

.step-content {
  flex-grow: 1;
}

.step-content h3 {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: #303133;
}

.step-info {
  color: #606266;
  font-size: 14px;
}

.step-info p {
  margin: 5px 0;
}

.step-line {
  position: absolute;
  left: 20px;
  top: 40px;
  width: 2px;
  height: calc(100% - 40px);
  background-color: #e4e7ed;
}

/* 完成状态 */
.completed .step-icon {
  background-color: #67c23a;
  color: #fff;
}

.completed .step-line {
  background-color: #67c23a;
}

/* 当前状态 */
.current .step-icon {
  background-color: #409EFF;
  color: #fff;
}

/* 待处理状态 */
.pending .step-icon {
  background-color: #f0f0f0;
  color: #909399;
}

@media screen and (max-width: 768px) {
  .process-container {
    padding: 16px;
  }

  .process-timeline {
    padding: 20px;
  }

  .step-content h3 {
    font-size: 14px;
  }

  .step-info {
    font-size: 12px;
  }
}

/* 无数据提示样式 */
.no-data {
  text-align: center;
  padding: 40px 0;
  color: #909399;
}

.no-data i {
  font-size: 48px;
  margin-bottom: 10px;
}

.no-data p {
  font-size: 16px;
  margin: 0;
}
</style> 